package com.zr.legalfactory.util;

import java.util.List;

/**
 * 
 * @ClassName: PageUtil
 * @Description: 分页的工具类
 * @author "Aiseek"
 * @date 2019年9月12日
 *
 */
public class PageUtil<T>{
	/**
	 * 当前页数(即当前是第几页)
	 */
	public Integer pageIndex;
	/**
	 * 每页显示多少条数据
	 */
	public Integer pageSize;
	/**
	 * 索引值(limit m,n中的m)
	 */
	public Integer offset;
	/**
	 * 总页数
	 */
	private Integer totalPage;
	/**
	 * 总的数据条数
	 */
	private Integer totalNumber;
	/**
	 * 某页显示的数据
	 */
	
	private List<T> dataList;
	
	public Integer getOffset(Integer pageIndex,Integer pageSize) {
		if (pageIndex==null) {
			pageIndex=1;
		}
		if (pageSize==null) {
			pageSize=5;
		}
		int index = (pageIndex - 1 ) * pageSize;
		setOffset(index);
		return offset;
	}
	
	
	
	public PageUtil() {
		super();
	}

	

	public PageUtil(Integer pageIndex, Integer pageSize, Integer offset, Integer totalPage, Integer totalNumber,
                    List<T> dataList) {
		super();
		this.pageIndex = pageIndex;
		this.pageSize = pageSize;
		this.offset = offset;
		this.totalPage = totalPage;
		this.totalNumber = totalNumber;
		this.dataList = dataList;
	}



	public Integer gettotalPage(Integer totalNumber,Integer pageSize) {
		Integer totalPage = (totalNumber%pageSize==0)?totalNumber/pageSize:totalNumber/pageSize+1;
		settotalPage(totalPage);
		return totalPage;
	}
	
	public Integer getpageIndex() {
		return pageIndex;
	}
	public void setpageIndex(Integer pageIndex) {
		this.pageIndex = pageIndex;
	}
	public Integer getpageSize() {
		return pageSize;
	}
	public void setpageSize(Integer pageSize) {
		this.pageSize = pageSize;
	}
	public Integer getOffset() {
		return offset;
	}
	public void setOffset(Integer offset) {
		this.offset = offset;
	}
	public Integer gettotalPage() {
		return totalPage;
	}
	public void settotalPage(Integer totalPage) {
		this.totalPage = totalPage;
	}
	public Integer gettotalNumber() {
		return totalNumber;
	}
	public void settotalNumber(Integer totalNumber) {
		this.totalNumber = totalNumber;
	}
	public List<T> getdataList() {
		return dataList;
	}
	public void setdataList(List<T> dataList) {
		this.dataList = dataList;
	}
}
